package com.suxiaoxiao.springbootlearn.designpattern.observerpattern.observer;

import com.suxiaoxiao.springbootlearn.designpattern.observerpattern.subject.Subject;

/**
 * 目前状况的布告板
 * @author 、
 */
public class CurrentConditionsDisplay implements Observer, DisplayElement {

    /**
     * 温度
     */
    private float temperature;
    /**
     * 湿度
     */
    private float humidity;

    /**
     * 订阅的主题
     */
    private Subject weatherData;

    /**
     * 初始化的时候注册为观察者
     * @param weatherData
     */
    public CurrentConditionsDisplay(Subject weatherData) {
        this.weatherData = weatherData;
        weatherData.registerObserver(this);
    }

    /**
     * 显示方法
     */
    @Override
    public void display() {
        System.out.println("当前状态的布告板" + temperature + "F degrees and " + humidity + "% humidity");
    }

    /**
     * 通知时调用的方法
     * @param temp 温度
     * @param humidity 湿度
     * @param pressure 气压
     */
    @Override
    public void update(float temp, float humidity, float pressure) {
        this.temperature = temp;
        this.humidity = humidity;
        display();
    }

}
